/// @tags: dij SPT Shortest Path Tree
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>

inline int read() {
  int res = 0;
  bool flag = 0;
  char c = getchar();
  while (c < '0' or c > '9') {
    if (c == '-') flag = 1;
    c = getchar();
  }
  while (c >= '0' and c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  return flag ? -res : res;
}

const int N = 1e5 + 5, M = 2e5 + 5;
int n, m;
int dis[N], A[M], B[M], C[M], from[N];
int fa[N], f[N], ans[N];
int e_cnt, heads[N];
bool ontree[M << 1];

struct Edge {
  int nxt, v, w;
  Edge() {}
  Edge(int u, int v, int w) : nxt(u), v(v), w(w) {}
  inline bool operator<(const Edge &rhs) const { return w < rhs.w; }
} e[M << 1], g[M << 1];

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}

inline int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }

/// @brief 寻找树上父亲
void dfs(int u) {
  for (int i = heads[u], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != fa[u]) fa[v] = u, dfs(v);
  }
}

struct Node {
  int x, d;
  Node(int x, int d) : x(x), d(d) {}
  inline bool operator<(const Node &rhs) const { return d > rhs.d; }
};

inline void dij(int s) {
  std::priority_queue<Node> q;
  memset(dis, 0x3f, sizeof(dis));
  q.emplace(s, dis[s] = 0);
  while (!q.empty()) {
    int u = q.top().x, d = q.top().d;
    q.pop();
    if (dis[u] != d) continue;
    for (int i = heads[u], v; i; i = e[i].nxt) {
      if (dis[v = e[i].v] > dis[u] + e[i].w) {
        from[v] = i;
        dis[v] = dis[u] + e[i].w;
        q.emplace(v, dis[v]);
      }
    }
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen64("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen64("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P2934 [USACO09JAN]Safe Travel G.in", "r", stdin);
  freopen("P2934 [USACO09JAN]Safe Travel G.out", "w", stdout);
#endif
#endif

  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    A[i] = read(), B[i] = read(), C[i] = read();
    add(A[i], B[i], C[i]);
    add(B[i], A[i], C[i]);
  }
  dij(1);
  e_cnt = 0;
  memset(heads, 0, sizeof(heads));
  for (int i = 2; i <= n; ++i) {
    int x = (from[i] + 1) >> 1;
    add(A[x], B[x], 0), add(B[x], A[x], 0);
    ontree[x] = true;
  }
  dfs(1);
  int num = 0;
  for (int i = 1; i <= m; i++) {
    if (ontree[i]) continue;
    g[++num] = Edge(A[i], B[i], dis[A[i]] + dis[B[i]] + C[i]);
  }
  std::sort(g + 1, g + num + 1);
#define u nxt
  for (int i = 1; i <= n; i++) f[i] = i, ans[i] = -1;
  for (int i = 1; i <= num; i++) {
    int x = g[i].u, y = g[i].v;
    x = find(x), y = find(y);
    while (x != y) {
      if (dis[x] < dis[y]) std::swap(x, y);
      ans[x] = g[i].w - dis[x];
      f[x] = fa[x];
      x = find(x);
    }
  }
#undef u
  for (int i = 2; i <= n; i++) { printf("%d\n", ans[i]); }
  return 0;
}